package jcore.callback;


/**
 * 
 * @author taowei20061122@163.com
 *
 */
public class A2 {
	//谓词，标示某个事件是否已发生
	private boolean somethingHappened = true;
	
	public void doMyJob(Callback action) {
		if (somethingHappened) {//检查设置的谓词，事件是否发生了
			
			//某事件发生后，调用实现了接口的对象的doJob方法去做一些特定的工作
			action.doJob();
		}
	}
	
/*	public void doJog(final String parameter) {
		
		class CallbackC implements Callback {
			public void doJob() {
				System.out.println(parameter);
			}
		}
		new CallbackC().doJob();
	}
	*/
	
/*	public void query(String sql,Callback callback) {
		query(sql, new B());
	}*/
	
	public void setSomethingHappened(boolean flag) {
		this.somethingHappened = flag;
	}
	
	class SomeCallback implements Callback {
		public void doJob() {
			//do some thing
			System.out.println("SomeCallback....");
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
/*		new A2().doJog("Callback...");
		A2 a = new A2();
		B b = new B();
		a.query("select * form user", b);*/
		

		
		A2 likeJdbcTemplate = new A2();
		//某个事件发生了，该发通知回调接口对象
		likeJdbcTemplate.setSomethingHappened(true);
		
		likeJdbcTemplate.doMyJob(likeJdbcTemplate.new SomeCallback());
	}

}
